<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>hls.js</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="hls.js/hls.min.js"></script>
</head>
<body>
<div style="width: 400px;height: 300px">
    <video id="video" controls></video>
</div>

<script>
    function initVideo() {
        let video = document.getElementById('video')
        if (Hls.isSupported()) {
            let hls = new Hls()
            //该hls地址为nginx配置中的地址
            hls.loadSource('https://cctvwbndbd.a.bdydns.com/cctvwbnd/cctv1_2/index.m3u8')
            hls.attachMedia(video)
            hls.on(Hls.Events.MANIFEST_PARSED, () => {
                video.play()
            });
        } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
            video.src = 'https://cctvwbndbd.a.bdydns.com/cctvwbnd/cctv1_2/index.m3u8'
            video.addEventListener('loadedmetadata', function () {
                video.play()
            })
        }
    }

    initVideo()

</script>
</body>

</html>
